<template>
  <div>
     <el-input v-model="hid"></el-input>
     <el-upload
       action="#"
       ref="mYupload"
       list-type="picture-card"
       :on-remove="handleRemove"
       :http-request="customUpload"
     >
       <i class="el-icon-plus"></i>
     </el-upload>
     <button @click="submitUpload">上传</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      add: {
        files: [],
        hid: []
      },
      hid: 39
    };
  },
  methods: {
    async submitUpload() {
      // this.add.hid = [];
      // for (let i = 0; i < this.add.files.length; i++) {
      //   this.add.hid.push(this.hid);
      // }
      
      let formData = new FormData();
      formData.append("files", this.add.files);
      formData.append("hid", this.hid);
      let ret = await this.$http.post('/admin/imginfo/upload',formData);
      console.log(ret);
    },
    handleRemove(file, fileList) {
      // 正确地更新files数组
      this.add.files = fileList;
    },
    customUpload(file) {
      // this.add.files.push(file.file);
      this.add.files = file.file;
    },
  }
}
</script>
